package logic

import (
	"center/centerrpc/centerrpc"
	"center/centerrpc/internal/svc"
	"center/models/mysql"
	"context"
	"gorm.io/gorm"

	"github.com/zeromicro/go-zero/core/logx"
)

type ListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListLogic {
	return &ListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ListLogic) List(in *centerrpc.ListRequest) (*centerrpc.ListResponse, error) {
	// todo: add your logic here and delete this line

	var user mysql.User
	mysql.DB.Debug().Where("id = ?", in.UserId).Find(&user)

	user = mysql.User{
		Model: gorm.Model{ID: user.ID},
	}
	mysql.DB.Debug().Find(&user)

	return &centerrpc.ListResponse{
		Account:  user.Account,
		Password: user.Password,
	}, nil
}
